#include "Spline.h"


void spline::read() 
{
  string filename;
  cout << "Input File Name" << endl;
  cin >> filename;
  filename = filename + ".txt";
  ifstream myfile;
  myfile.open(filename.c_str());
  if (myfile.is_open())
  {
    myfile >> order ;
    cout << "Number of points ";
	cout << order <<" " << endl << endl;
	spline::coordinates = new coordinate[order]; 
    //allocate the memory that an coordinate array the size of order would need
    // variable coordinates now points to the first element in that array
    for (int i = 0; i < order; i++)
    {
        myfile >> coordinates[i].x;
        myfile >> coordinates[i].y;
    //    cout << "Points: <" <<  coordinates[i].x << "," << coordinates[i].y << ">"<< endl;
        
    }
            
    
    myfile.close();
    return;
  }

  else cout << "Unable to open file"; 
}

void spline::output()
{
    string filename;
  cout << "Input File Name" << endl;
  cin >> filename;
  filename = filename + ".txt";
  ofstream myfile;
  myfile.open(filename.c_str());
  if (myfile.is_open())
  {
        myfile << (order-1)<< "\n";
   for(int r=0; r<order-1; r++)
      {
        
        myfile << coordinates[r].x << " " ;
        myfile << tempo[r].y << "\n";
    //    cout << "Points: <" <<  coordinates[i].x << "," << coordinates[i].y << ">"<< endl;
        
    }
            
    
    myfile.close();
    cout << " Finished Exporting" << endl;
    return;
  }
}
